package com.bzg.manager.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bzg.manager.exception.BaseException;
import com.bzg.manager.utils.RespBody;

/**
 * Description:统一异常处理
 *
 * @author gmy
 * @date 2017年3月3日 下午2:27:13
 */
public class BaseController {
	
	public static final Logger log = LoggerFactory.getLogger(BaseController.class);
	
	@ExceptionHandler(BaseException.class)
	@ResponseBody
	public RespBody exp(HttpServletRequest request,BaseException exception){
		log.error(String.format("{defineCode:%s, message:%s, request:%s}", exception.getDefineCode(), exception.getMessage(), request.getRequestURL()), exception);
		return RespBody.error(exception.getDefineCode(), exception.getMessage());
	}
}
